<template>
  <div class="user-profile">
    <!-- 导航栏 -->
    <van-nav-bar
    class="page-nav-bar"
    title="个人信息"
    left-arrow @click-left="$router.back()" />
    <!-- /导航栏 -->
    <input type="file" hidden ref="inputFile" @change="imageschange" >
    <van-cell @click="uploadphoto"  title="头像" is-link>
      <van-image
        class="avatar"
        fit="cover"
        round
        :src="obj.photo"
      />
    </van-cell>
    <van-cell @click="show1 = true" title="昵称" :value="obj.name" is-link />
    <van-cell @click="show2=true"  title="性别" :value="obj.gender?'女':'男'" is-link />
    <van-cell @click="show3 = true" title="生日" :value="obj.birthday" is-link />
    <!-- 编辑名字弹出层 -->
    <van-popup v-model="show1" position="bottom" :style="{ height: '100%' }" >
      <username v-if="show1" @onclose="show1=false" v-model="obj.name"/>
    </van-popup>
    <!-- 编辑性别的弹层 -->
    <van-popup v-model="show2" position="bottom"  >
      <user-sex v-if="show2" @close="show2=false" v-model="obj.gender" />
    </van-popup>
    <!-- 编辑生日弹层 -->
    <van-popup v-model="show3" position="bottom"  >
      <userbirthday  v-if="show3" @close='show3=false' v-model="obj.birthday"></userbirthday>
    </van-popup>
    <!-- 编辑头像弹层 -->
    <van-popup v-model="show4" style="height:100%" position="bottom"  >
      <user-photo v-if="show4" @load-photo="obj.photo=$event" @close='show4=false' :img="imgsrc"/>
    </van-popup>

  </div>
</template>
<script>
import { edituserinfo } from '@/api/getverify'
import Username from '../User/components/Username.vue'
import UserSex from '../User/components/UserSex.vue'
import Userbirthday from '../User/components/Userbirthday.vue'
import UserPhoto from '../User/components/UserPhoto.vue'
export default {
  components: { Username, UserSex, Userbirthday, UserPhoto },
  data () {
    return {
      obj: {},
      show1: false,
      show2: false,
      show3: false,
      show4: false,
      imgsrc: ''

    }
  },

  created () {
    this.loaduserprofile()
  },

  methods: {
    async loaduserprofile () {
      const res = await edituserinfo()
      // console.log(res)
      this.obj = res
    },
    uploadphoto () {
      this.$refs.inputFile.click()
    },
    imageschange (e) {
      if (e.target.value === '') return
      this.show4 = true
      this.imgsrc = URL.createObjectURL(this.$refs.inputFile.files[0])
      e.target.value = ''
    }
  }
}
</script>

<style scoped lang='less'>
.user-profile {
  .avatar {
    width: 60px;
    height: 60px;
  }
  /deep/.van-nav-bar__arrow {
    color: #fff;
  }
}
</style>
